import asyncio
import websockets
from flask import Flask,request
app = Flask(__name__)
#app.config['MAX_CONTENT_LENGTH'] = 100*1024*1024
loop = asyncio.get_event_loop()

async def hello(message):
    # 连接 websocket 并发送消息 获取相应
    async with websockets.connect("ws://127.0.0.1:5678") as websocket:
        await websocket.send(message)
        return await websocket.recv()

def get_encrypt(message):
    return str(loop.run_until_complete(hello(message)))

@app.route('/',methods = ['POST', 'GET'])
def hello_world():
    if request.method == 'POST':
        encrypt_txt = request.form.get('encrypt_txt')
        return get_encrypt(encrypt_txt)

if __name__ == '__main__':
    app.run(host="0.0.0.0",port=80,debug=True)
